package com.jc.oss.controller;

import com.jc.oss.entity.Result;
import com.jc.oss.service.FileService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author gongjiawei
 * @Date 2024/9/4 16:24
 * @注释
 */
@RestController
public class FileController {
    @Resource
    private FileService fileService;

    //@Value(value = "${storage.service.type}")
    //@NacosValue(value = "${storage.service.type}",autoRefreshed = true)
    //private String storageType;


    @RequestMapping("/test")
    public List<String> test() throws Exception {
        List<String> all=fileService.getAllBucket();
        return all;

    }
//    @RequestMapping("/testNacos")
//    public String testnacos() throws Exception {
//        return storageType;
//
//    }
    @RequestMapping("/testAll")
    public String testAll() throws Exception {
        //System.out.println(storageType);
        List<String> all=fileService.getAllBucket();
        return all.get(0);
    }


    @RequestMapping("/getUrl")
    public String getUrl(String bucketName, String objectName) throws Exception {
        return fileService.getUrl(bucketName, objectName);
    }

    /**
     * 上传文件
     */
    @RequestMapping("/upload")
    public Result upload(MultipartFile uploadFile, String bucket, String objectName) throws Exception {
        String url = fileService.uploadFile(uploadFile, bucket, objectName);
        return Result.ok(url);
    }


}
